<template>
  <div class="body-item-li">
    <div style="width: 100%;height: 100%">
      <el-skeleton
        v-if="temp.id === undefined || temp.id === null"
        style="padding: 20px;box-sizing: border-box"
        :rows="height"
      />
      <template-new :temp="temp" />
    </div>
  </div>
</template>
<script>
import { getToken } from '@/utils/auth'
import { queryEntity, queryGuestEntity } from '@/api/portal/manager/columnSet'
import TemplateNew from '@/template/index'
export default {
  name: 'PortalNewBodyItem', // 栏目组件
  components: { TemplateNew },
  props: {
    height: {
      type: Number,
      default: 4
    },
    column: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      defaultColumn: {
        x: 0,
        y: 0,
        w: 6,
        h: 8,
        menu: {
          id: this.menu
        }
      },
      rowId: [],
      temp: {
        column: {
          id: this.column
        }
      },
      style: {}
    }
  },
  watch: {
    column: {
      handler(newName, old) {
        this.initColumnSet(newName)
      },
      immediate: true
    }
  },
  methods: {
    initColumnSet(id) {
      if (getToken()) {
        queryEntity({ id: id })
          .then(res => {
            const { data } = res
            if (undefined !== data && data !== null) {
              this.temp = data
            }
          })
          .catch(() => {
            this.temp = { column: { id: this.column }}
          })
      } else {
        queryGuestEntity({ id: id })
          .then(res => {
            const { data } = res
            if (undefined !== data && data !== null) {
              this.temp = data
            }
          })
          .catch(() => {
            this.temp = { column: { id: this.column }}
          })
      }
    }
  }
}
</script>
<style scoped>
.body-item-li {
  width: 100%;
  height: 100%;
  padding: 0;
  box-sizing: border-box;
}
.body-item-li:hover {
  display: flex;
  flex-flow: row nowrap;
}
</style>
